<?php
/*************************************************************************************
 *
 *	FileName: /edp/lib/functions/preload.php
 *	Desc    : All the functions defined here would be loaded in the first part of the
 * 			  entire application.
 *	Author  : Seal
 *	Date    : 2009-10-17
 *
 *************************************************************************************/

//function edp_exit() 
//{
//   
//   session_write_close();
//   exit();
//}


/**********************************************************
 *	
 * 	Bellow two functions are responsible to handle error and
 * 	exceptions. Do not move these two functions to anywhere
 *  else!
 * 
 *	Seal Created by 2009-10-17
 **********************************************************/

function edp_error_handler ( $errno, $errstr, $errfile, $errline, $errcontext )
{
	
	$error =  "Error_handler: " . $errno . ':' . $errstr . ':' . $errfile. ':' . $errline . ':' . $errcontext;
	$Logger = GetLogger();
	$Logger->error( $error );
	
	
	/**********************************************************
	 *
	 * In the debug phase, we just return false to the system 
	 * handler. While published, we must log the error info and
	 * call the edp_exit() to exit script.
	 *
	 * 	edp_exit();
	 * 	
	 **********************************************************/
	
	return false;
}

function exception_handler( $exception ) 
{
	/**********************************************************
	 *
	 * In the debug phase, we just echo the original
	 * exception to diagnose the cause. While published, we 
	 * must log the error info and call the edp_exit() to exit 
	 * script.
	 *
	 * 	edp_exit();
	 * 	
	 **********************************************************/
   
	if( !($exception instanceof DBException) ) {
		$error =  "Exception: " . $exception->getMessage();
		$Logger = GetLogger();
		$Logger->error( $error );
	}
}


function page_exit_handler()
{
		global $page_base, $RCPSMatrix, $allowNextCommit;
		if( (in_array($page_base, $RCPSMatrix) && count($_POST) > 0) &&
			 	$allowNextCommit == 0 )
			edp_unset_session( $page_base );
		
}

?>